package org.apache.http.entity.mime.content;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import org.apache.http.a.a;
import org.apache.http.entity.b;

public class c extends a {
    private final byte[] a;

    public c(String str, b bVar) {
        super(bVar);
        a.a((Object) str, "Text");
        Charset b = bVar.b();
        String name = b != null ? b.name() : org.apache.http.a.b.name();
        try {
            this.a = str.getBytes(name);
        } catch (UnsupportedEncodingException e) {
            throw new UnsupportedCharsetException(name);
        }
    }

    public long getContentLength() {
        return (long) this.a.length;
    }

    public String getFilename() {
        return null;
    }

    public String getTransferEncoding() {
        return "8bit";
    }

    public void writeTo(OutputStream outputStream) throws IOException {
        a.a((Object) outputStream, "Output stream");
        InputStream byteArrayInputStream = new ByteArrayInputStream(this.a);
        byte[] bArr = new byte[4096];
        while (true) {
            int read = byteArrayInputStream.read(bArr);
            if (read != -1) {
                outputStream.write(bArr, 0, read);
            } else {
                outputStream.flush();
                return;
            }
        }
    }
}
